<script setup>
import { ref } from 'vue'
import BlogList from '@/components/blog/BlogList.vue'
import DailyAdvice from '@/components/blog/DailyAdvice.vue'
import RankList from '@/components/blog/RankList.vue'

const tabs = ref(['前端', '后端', '算法', '工具', '随笔', '其他'])
const activeTab = ref(0)

defineOptions({
  name: 'BlogIndex',
})
</script>

<template>
  <div class="container">
    <!-- 左侧标签栏 -->
    <div class="left">
      <ul>
        <li
          v-for="(tab, index) in tabs"
          :key="index"
          :class="{ active: activeTab == index }"
          @click="activeTab = index"
        >
          {{ tab }}
        </li>
      </ul>
    </div>

    <!-- 中间内容区域 -- 文章列表 -->
    <div class="center">
      <BlogList />
    </div>

    <!-- 右侧内容区域(每日名言 + 文章排行) -->
    <div class="right">
      <DailyAdvice />
      <RankList />
    </div>

    <el-backtop :right="50" :bottom="50" />
  </div>
</template>

<style scoped lang="scss">
.container {
  padding: 20px 50px;
  display: grid;
  grid-template-columns: 1fr 3fr 1fr;
  grid-column-gap: 16px;

  .left {
    align-self: start;
    position: sticky;
    top: 80px;
    display: flex;
    flex-direction: column; // ✅ 如果要保留 flex，一定要让它垂直布局
    align-items: flex-end; // ✅ 实现右对齐
    ul {
      height: auto;
      display: flex;
      flex-direction: column;
      align-items: center;
      width: 60%;
      padding: 10px;
      background-color: white;
      border-radius: 5px;

      li {
        width: 90%;
        height: 40px;
        margin-top: 5px;
        line-height: 40px;
        font-weight: 500;
        font-size: 14px;
        text-align: center;

        &.active {
          color: #1e80ff;
          background-color: rgba(30, 128, 255, 0.1);
          border-radius: 8px;
          font-weight: 600;
        }

        &:hover {
          background-color: #f5f5f5;
        }
      }
    }
  }
  .center {
    padding: 16px;
    background-color: white;
    border-radius: 5px;
  }

  .right {
    align-self: start;
    position: sticky;
    top: 80px;
    display: flex;
    flex-direction: column;
    gap: 16px;
  }
}

@media (max-width: 1400px) {
  .container {
    grid-template-columns: 3fr 1fr;
    .left {
      display: none;
    }
  }
}

@media (max-width: 1200px) {
  .container {
    grid-template-columns: 1fr;
    .left {
      display: none;
    }
    .right {
      display: none;
    }
  }
}
</style>
